package com.huaboot.system.controller;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import com.huaboot.commont.core.BaseResponse;
import com.huaboot.commont.core.ResultUtils;
import com.huaboot.system.convert.SysUserTokenConvert;
import com.huaboot.system.entity.SysUserTokenEntity;
import com.huaboot.system.service.SysUserTokenService;
import com.huaboot.system.query.SysUserTokenQuery;
import com.huaboot.system.vo.SysUserTokenVO;
//import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import com.huaboot.commont.page.PageResult;
import java.util.List;

/**
* 用户Token
*
* @author ff xxx
* @since 1.0.0 2023-09-04
*/
@RestController
@RequestMapping("system/token")
@Tag(name="用户Token")
@AllArgsConstructor
public class SysUserTokenController {
    private final SysUserTokenService sysUserTokenService;

    @GetMapping("page")
    @Operation(summary = "分页")
    @PreAuthorize("hasAuthority('system:token:page')")
    public BaseResponse<PageResult<SysUserTokenVO>> page(SysUserTokenQuery query){
        return ResultUtils.success(sysUserTokenService.page(query));
    }

    @GetMapping("{id}")
    @Operation(summary = "信息")
    @PreAuthorize("hasAuthority('system:token:info')")
    public BaseResponse<SysUserTokenVO> get(@PathVariable("id") Long id){
        SysUserTokenEntity entity = sysUserTokenService.getById(id);

        return ResultUtils.success(SysUserTokenConvert.INSTANCE.convert(entity));
    }

    @PostMapping
    @Operation(summary = "保存")
    @PreAuthorize("hasAuthority('system:token:save')")
    public BaseResponse<?> save(@RequestBody SysUserTokenVO vo){
        sysUserTokenService.save(vo);

        return ResultUtils.success("新增成功");
    }

    @PutMapping
    @Operation(summary = "修改")
    @PreAuthorize("hasAuthority('system:token:update')")
    public BaseResponse<?> update(@RequestBody  SysUserTokenVO vo){
        sysUserTokenService.update(vo);

        return ResultUtils.success("修改成功");
    }

    @DeleteMapping
    @Operation(summary = "删除")
    @PreAuthorize("hasAuthority('system:token:delete')")
    public BaseResponse<?> delete(@RequestBody List<Long> idList){
        sysUserTokenService.delete(idList);

        return ResultUtils.success("删除成功");
    }
}
